package com.yang.vegetablessource.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yang.vegetablessource.R;
import com.yang.vegetablessource.beans.WorkingInfo;

/**
 * 
 * @ClassName: WorkingInfoAdapter
 * @Description: 显示工作信息
 * @author YZL
 * @date 2013-4-17 下午9:30:48
 */
public class WorkingInfoAdapter extends BaseAdapter {

	private Context mContext;
	private List<WorkingInfo> list;

	public WorkingInfoAdapter(Context mContext, List<WorkingInfo> list) {
		this.mContext = mContext;
		this.list = list;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public class ViewHolder {
		ImageView work_image;
		TextView worker_name;
		TextView work_time;
		TextView work_type;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {

			convertView = View.inflate(mContext, R.layout.workinginfo_item,
					null);
			holder = new ViewHolder();
			holder.work_image = (ImageView) convertView
					.findViewById(R.id.work_image);
			holder.worker_name = (TextView) convertView
					.findViewById(R.id.worker_name);
			holder.work_time = (TextView) convertView
					.findViewById(R.id.work_time);
			holder.work_type = (TextView) convertView
					.findViewById(R.id.work_type);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		WorkingInfo info = list.get(position);

		holder.work_image.setImageResource(info.imageId);
		holder.worker_name.setText(info.workerName);
		holder.work_time.setText(info.workTime);
		holder.work_type.setText(info.workType);
		
		 
		  // 第一项
		   if (position == 0) {
			   convertView.setBackgroundResource(R.drawable.shape_top_corner_no_bottom_line);
		  }else if (position == getCount() - 1) {
		  // 最后一项
			  convertView.setBackgroundResource(R.drawable.shape_bottom_corner_no_top_line);
		  } else {
			  convertView.setBackgroundResource(R.drawable.shape_no_corner_without_bottom);
		  }
		  

		return convertView;
	}

}
